home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Audio-DSP / NU / Source / FileCell.m < prev    next >
Encoding:
Text File  |  1992-11-25  |  2.9 KB  |  101 lines

  1. #import "FileCell.h"
  2. #import <appkit/NXImage.h>
  3. #import <appkit/Application.h>
  4. #import <appkit/View.h>
  5. #import <dpsclient/dpsNeXT.h>
  6. #import <appkit/NXHelpPanel.h>
  7. #import "MenuManager.h"
  8.  
  9. @implementation FileCell: Cell
  10. { id controlView, image ;
  11.   char fileName[128] ;
  12. }
  13.  
  14. - calcCellSize:(NXSize *)aSize ;
  15. { aSize->height = aSize->width = 48.0;
  16.   return self;
  17. }
  18.  
  19. - drawSelf: (const NXRect *)cellFrame inView:controlView ;
  20. { char *directory,*file,*fullPath ;
  21.   int pathLength ;
  22.   id controlWindow ;
  23.   NXPoint origin = cellFrame->origin ;
  24.   origin.y += cellFrame->size.height ;
  25.   controlWindow = [controlView window] ;
  26.   if([controlWindow isKindOf: [NXHelpPanel class]])
  27.   { // pain in the butt to get filename from a help panel
  28.     directory = [controlWindow helpDirectory] ;
  29.     file = [controlWindow helpFile] ;
  30.     pathLength = strlen(directory) + strlen(file) + strlen(fileName) ;
  31.     fullPath = (char *) alloca(pathLength + 3) ;
  32.     sprintf(fullPath,"%s/%s/%s",directory,file,fileName) ;
  33.   }
  34.   else
  35.   { // much easier to get it from a workspace
  36.     directory = [controlWindow fileName] ;
  37.     pathLength = strlen(directory) + strlen(fileName) ;
  38.     fullPath = (char *) alloca(pathLength + 2) ;
  39.     sprintf(fullPath,"%s/%s",directory,fileName) ;
  40.   }
  41.   support = [[Application workspace] getIconForFile: fullPath] ;
  42.   [support composite:NX_COPY toPoint:&origin] ;
  43.   return self ;
  44. }
  45.  
  46. - highlight:(const NXRect *)cellFrame inView:controlView lit:(BOOL)flag;
  47. {
  48. #ifdef DEBUG
  49.   fprintf(stderr,"FileCell.m  highlight inView lit\n");
  50. #endif DEBUG
  51.   return self;
  52. }
  53.  
  54. - initFromFile: (char *) filename controlView: aView image: anImage ;
  55. { char *index ;
  56.   [super init] ;
  57.   index = rindex(filename,"/") ; // point index at filename minus
  58.   index++ ; // the path
  59.   strcpy(fileName, index) ; // copy into the ivar
  60.   controlView = aView ;
  61.   image = anImage ;
  62.   return self ;
  63. }
  64.  
  65. - (BOOL)trackMouse:(NXEvent *)theEvent inRect:(const NXRect *) cellFrame ofView:aView;
  66. { static    long lastDown = 0 ; 
  67.   // if the user clicks down in less than .33 secs (20 intervals)
  68.   // then lets treat it as a double click
  69.   if (theEvent->time-lastDown < 20)
  70.   { id helpPanel ;
  71.     char *helpPath, *helpFile, *fullPath ;
  72.     int pathLength ;
  73.     helpPanel = [controlView window] ;
  74.     helpPath = [helpPanel helpDirectory] ;
  75.     helpFile = [helpPanel helpFile] ;
  76.     pathLength = strlen(helpPath) + strlen(helpFile) + strlen(fileName) ;
  77.     fullPath = (char *) alloca(pathLength + 1) ;
  78.     sprintf(fullPath,"%s/%s/%s",helpPath,helpFile,fileName) ;
  79.     [[Application workspace] openFile:fullPath] ;
  80.   }
  81.   lastDown = theEvent->time;
  82.   // should allow drag out here 
  83.   return YES;
  84. }
  85.  
  86. // read attached filename and fetch its Image
  87. // should test for errors 
  88. - readRichText:(NXStream *)stream forView:view ;
  89. { NXScanf(stream, "%s\n", fileName) ; 
  90.   controlView = view ;
  91.   return self ;
  92. }
  93.  
  94. // just write out the name of the attached file
  95. - writeRichText:(NXStream *)stream forView:view ;
  96. { NXPrintf(stream, "%s\n",fileName);
  97.   return self;
  98. }
  99.  
  100.  
  101.